package cn.iocoder.yudao.framework.common.util.date;

import cn.hutool.core.date.DateUtil;

import java.time.Duration;
import java.time.LocalDateTime;

public class UTCDateUtils {

    /**
     * 一天的毫秒数
     */
    public static Long DAY_MILLS = Duration.ofDays(1).toMillis();

    public static Long toTimeStampUTC(LocalDateTime localDateTime) {
        if (localDateTime == null) {
            return null;
        }
        return localDateTime.toEpochSecond(java.time.ZoneOffset.UTC) * 1000;
    }

    public static LocalDateTime toLocalDateTimeUTC(Long timestamp) {
        if (timestamp == null) {
            return null;
        }
        return LocalDateTime.ofEpochSecond(timestamp / 1000, 0, java.time.ZoneOffset.UTC);
    }

    public static LocalDateTime now() {
        return toLocalDateTimeUTC(System.currentTimeMillis());
    }

    public static String formatUTC(LocalDateTime localDateTime) {
        return DateUtil.format(localDateTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + " (UTC+0)";
    }

    public static String formatUTC(Long timestamp) {
        return DateUtil.format(toLocalDateTimeUTC(timestamp), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
            + " (UTC+0)";
    }
}
